/* filesys.h : dgnsc file system func
 * Copyright (C) 2009-2010 drangon <drangon.zhou@gmail.com>
 * 2011-02
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_DGNSC_FILESYS_H
#define INCLUDED_DGNSC_FILESYS_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef void * dgn_file_t;

enum {
	DGN_O_DEFAULT = 0,  // default : open exist, read only
	DGN_O_OPEN_READ = 0,
	DGN_O_OPEN_WRITE = 1, // open exist, read/write
	DGN_O_OPEN_CREATE = 2,     // open exist or create new, read/write
	DGN_O_CREATE_EXCL = 3, // like DGN_O_CREATE, but failed if already exist
};

enum {
	DGN_SEEK_SET,   // set offset
	DGN_SEEK_CUR,   // offset relate to current position
	DGN_SEEK_END,   // offset relate to file end ( usually neg )
};

dgn_file_t dgn_file_open( const char * name, int create_flag );
int64_t dgn_file_seek( dgn_file_t fd, int64_t off, int where );
int dgn_file_read( dgn_file_t fd, char * buf, int len );
int dgn_file_write( dgn_file_t fd, const char * buf, int len );
int dgn_file_lock( dgn_file_t fd );
int dgn_file_unlock( dgn_file_t fd );
int dgn_file_truncate( dgn_file_t fd, int64_t off );
int dgn_file_close( dgn_file_t fd );

int dgn_file_rm( const char * name );

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // INCLUDED_DGNSC_FILESYS_H

